package com.itheima.practice04;

import java.util.TreeMap;

//TreeMap案例（按年龄排序）
public class TreeMapTest {
    public static void main(String[] args) {

        TreeMap<Student, String> treeMap = new TreeMap<>();

       /* TreeMap<Student,String> treeMap = new TreeMap<>((o1,o2) -> {
            int result = o1.getAge()-o2.getAge();
            result = result == 0? o1.getName().compareTo(o2.getName()):result;
            return result;
        });*/

        Student student1 = new Student("三藏", 31);
        Student student2 = new Student("三藏", 31);
        Student student3 = new Student("悟空", 5000);
        Student student4 = new Student("八戒", 3200);
        Student student5 = new Student("白骨精", 1600);
        treeMap.put(student1, "东土大唐");
        treeMap.put(student2, "东土大唐");
        treeMap.put(student3, "石头");
        treeMap.put(student4, "高老庄");
        treeMap.put(student5, "白骨洞");

        treeMap.forEach((student, adress) -> {
            System.out.println(student + "" + adress);
        });
    }
}
